package com.andy.wang.controller;

import com.alibaba.fastjson.JSONObject;
import com.andy.wang.pojo.Result;
import com.andy.wang.pojo.User;
import com.andy.wang.service.UserService;
import com.andy.wang.utils.UploadFile;
import com.andy.wang.utils.redis.RedisUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.*;
import java.io.UnsupportedEncodingException;
import java.util.UUID;

@RestController
@CrossOrigin
@RequestMapping("/login")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RedisUtils redisUtils;
    /**
     * 用户注册
     */
    @RequestMapping(value = "/register/{imgType}",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public int login(@RequestBody User user, @PathVariable(value = "imgType",required = false) String imgType) throws UnsupportedEncodingException {
        return userService.insertSelective(user,imgType);
    }
    //使用session存储用户数据
    @PostMapping("/session/{phone}")
    public User session(@PathVariable("phone") String phone, HttpServletRequest request){
        return userService.sessionPhone(phone,request);
    }
}
